from flask import Flask, Blueprint,request, jsonify ,send_file,render_template
import sys
import json



import os
import datetime
import librosa
import soundfile as sf

from utils  import util
from utils  import qwen_util


# from  ..service.index_service_1  import  hello

from pathlib import Path
# 动态添加utils文件夹的路径
current_file_path = Path(os.path.abspath(__file__))
parent_dir = current_file_path.parent.parent
print(parent_dir)
sys.path.append(os.path.join(parent_dir, 'service'))
from  service  import  recordingMinutesService


recordingMinutes = Blueprint("recordingMinutes", __name__)




@recordingMinutes.route("/recordPage", methods=['GET','POST'])
def recordingMinutes_recordPage():

    """
    :功能: 录音纪要页面初始化接口
    :param name: 参数的注释信息
    :return: 函数的返回值
    """

    print("   recordPage  ")
    return render_template('recordPage.html')



@recordingMinutes.route("/convert_to_aac_save_test", methods=['GET','POST'])
def recordingMinutes_convert_to_aac_save_test():

    """
    :功能: 录音纪要页面初始化接口
    :param name: 参数的注释信息
    :return: 函数的返回值
    """

    print("    convert_to_aac_save   ")



    print("convert-to-aac 请求收到")
    if 'audio' not in request.files:
        return '没有音频文件', 400

    audio_file = request.files['audio']

    # 获取录制信息
    total_duration = request.form.get('total_duration', 0)
    actual_duration = request.form.get('actual_duration', 0)
    pause_count = request.form.get('pause_count', 0)

    print(f"录制信息 - 总时长: {total_duration}s, 有效录制: {actual_duration}s, 暂停次数: {pause_count}")

    # 返回AAC文件给用户下载
    # return send_file(
    #     aac_buffer,
    #     as_attachment=True,
    #     download_name=f'{base_filename}.aac',
    #     mimetype='audio/aac'
    # )

    recordingMinutesService.recordingMinutes_convert_to_aac_save_test(audio_file,total_duration,actual_duration,pause_count)

    return  "convert_to_aac_save"









